package base.day26.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class ReceptionDemo2 {
    public static void main(String[] args) throws IOException {
        MulticastSocket ms = new MulticastSocket(10002);
        //创建包接受数据
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

        //把当前计算机绑定一个组播地址哦，，表示添加到这一组中
        ms.joinGroup(InetAddress.getByName("224.0.1.0"));
        //将数据添加到包中
        ms.receive(dp);
        //得到数据
        byte[] data = dp.getData();
        int length = dp.getLength();
        System.out.println(new String(data,0,length));
    }
}
